import { ICommonParams } from '../../interfaces';
import log from '../logger/log';

export default function page(page_name: string, spaceid: string, url: string, msg: ICommonParams, actionid: string, sessionid: string) {
	log('file_name:' + page_name, __filename);
	const headers = { actionid, sessionid, spaceid };
	try {
		const file_path = `@feidao-works/${spaceid}/js/${page_name}/n`;
		log('page file:' + file_path);
		return require(file_path).default(url, msg, headers);
	} catch (e) {
		// 本地开发模式
		log('failed when require module, message:' + e, __filename);
		log('try get file in dist', __filename);
		return require(require.resolve(`${page_name}/n`, { paths: ['./dist/src-web/', './dist/src-h5/'] })).default(url, msg, headers);
	}
}
